# Import Libraries
import seaborn as sns
import numpy
import matplotlib.pyplot as plt
# sns.set_style(style=None,rc=None)
# Load dataset
ship = sns.load_dataset('titanic')
ship
# Change figure
plt.figure(figsize=(6,3))
#draw a line plot
sns.barplot(x="class",y="fare",hue="sex",data=ship,ci=None,
estimator=lambda x: x.mean(),saturation=1)
plt.title("Plot of Titanic alone Male and Females")
# sns.set_style("dark")
plt.show()
# importing the required libraries
import seaborn as sns
import matplotlib.pyplot as plt
# read a titanic.csv file
# from seaborn library
ship = sns.load_dataset("titanic")
sns.barplot(x="fare",y="class",hue="sex",data=ship,saturation=1)
plt.show()
# importing the required libraries
import seaborn as sns
import matplotlib.pyplot as plt
# read a titanic.csv file
# from seaborn library
ship = sns.load_dataset("titanic")
sns.barplot(x="class",y="fare",data=ship,
linewidth=2.5,facecolor=(0,1,0.6,1),
errcolor="0",edgecolor=".7")
plt.show()
# import libraries
import seaborn as sns
# canvas (baloon board)
sns.set(style="whitegrid")
ship = sns.load_dataset("titanic")
sns.boxplot(x="class",y="fare",data=ship)
plt.show()
# import libraries
import seaborn as sns
# canvas (baloon board)
sns.set(style="whitegrid")
tip = sns.load_dataset("tips")
tip
sns.boxplot(x="sex",y="tip",data=tip)
plt.show()
# import libraries
import seaborn as sns
import matplotlib.pyplot as plt
# canvas (baloon board)
sns.set(style="whitegrid")
tip = sns.load_dataset("tips")
tip
sns.boxplot(x="day",y="tip",data=tip,saturation=1)
plt.show()
#libraries
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
tip = sns.load_dataset("tips")
tip
| total_bill | tip | sex | smoker | day | time | size | |
|---|---|---|---|---|---|---|---|
| 0 | 16.99 | 1.01 | Female | No | Sun | Dinner | 2 |
| 1 | 10.34 | 1.66 | Male | No | Sun | Dinner | 3 |
| 2 | 21.01 | 3.50 | Male | No | Sun | Dinner | 3 |
| 3 | 23.68 | 3.31 | Male | No | Sun | Dinner | 2 |
| 4 | 24.59 | 3.61 | Female | No | Sun | Dinner | 4 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 239 | 29.03 | 5.92 | Male | No | Sat | Dinner | 3 |
| 240 | 27.18 | 2.00 | Female | Yes | Sat | Dinner | 2 |
| 241 | 22.67 | 2.00 | Male | Yes | Sat | Dinner | 2 |
| 242 | 17.82 | 1.75 | Male | No | Sat | Dinner | 2 |
| 243 | 18.78 | 3.00 | Female | No | Thur | Dinner | 2 |
244 rows × 7 columns
#libraries
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
tip = sns.load_dataset("tips")
tip.describe()
| total_bill | tip | size | |
|---|---|---|---|
| count | 244.000000 | 244.000000 | 244.000000 |
| mean | 19.785943 | 2.998279 | 2.569672 |
| std | 8.902412 | 1.383638 | 0.951100 |
| min | 3.070000 | 1.000000 | 1.000000 |
| 25% | 13.347500 | 2.000000 | 2.000000 |
| 50% | 17.795000 | 2.900000 | 2.000000 |
| 75% | 24.127500 | 3.562500 | 3.000000 |
| max | 50.810000 | 10.000000 | 6.000000 |
#libraries
import seaborn as sns
sns.set(style="whitegrid")
# loading data-set
tip = sns.load_dataset("tips")
sns.boxplot(y=tip["tip"])
plt.show()
#libraries
import seaborn as sns
import matplotlib.pyplot as plt
# use to set style of background of plot
sns.set(style="whitegrid")
# loading data-set
tip = sns.load_dataset("tips")
sns.boxplot(x="day", y="tip", hue="smoker",data=tip)
plt.show()
#libraries
import seaborn as sns
import matplotlib.pyplot as plt
# use to set style of background of plot
sns.set(style="whitegrid")
# loading data-set
tip = sns.load_dataset("tips")
sns.boxplot(x="day", y="tip", hue="smoker",data=tip,
palette="Set2",dodge=True)
# Dodge=smoker plot side by side
plt.show()
#libraries
import seaborn as sns
import matplotlib.pyplot as plt
# use to set style of background of plot
sns.set(style="whitegrid")
# loading data-set
tip = sns.load_dataset("tips")
sns.boxplot(x="day", y="tip", hue="smoker",data=tip,
color="#2b7cff")
plt.show()
# libraries
import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
ship = sns.load_dataset("titanic")
# ship.head() # Show first five
ship.head(10)
| survived | pclass | sex | age | sibsp | parch | fare | embarked | class | who | adult_male | deck | embark_town | alive | alone | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 3 | male | 22.0 | 1 | 0 | 7.2500 | S | Third | man | True | NaN | Southampton | no | False |
| 1 | 1 | 1 | female | 38.0 | 1 | 0 | 71.2833 | C | First | woman | False | C | Cherbourg | yes | False |
| 2 | 1 | 3 | female | 26.0 | 0 | 0 | 7.9250 | S | Third | woman | False | NaN | Southampton | yes | True |
| 3 | 1 | 1 | female | 35.0 | 1 | 0 | 53.1000 | S | First | woman | False | C | Southampton | yes | False |
| 4 | 0 | 3 | male | 35.0 | 0 | 0 | 8.0500 | S | Third | man | True | NaN | Southampton | no | True |
| 5 | 0 | 3 | male | NaN | 0 | 0 | 8.4583 | Q | Third | man | True | NaN | Queenstown | no | True |
| 6 | 0 | 1 | male | 54.0 | 0 | 0 | 51.8625 | S | First | man | True | E | Southampton | no | True |
| 7 | 0 | 3 | male | 2.0 | 3 | 1 | 21.0750 | S | Third | child | False | NaN | Southampton | no | False |
| 8 | 1 | 3 | female | 27.0 | 0 | 2 | 11.1333 | S | Third | woman | False | NaN | Southampton | yes | False |
| 9 | 1 | 2 | female | 14.0 | 1 | 0 | 30.0708 | C | Second | child | False | NaN | Cherbourg | yes | False |
# libraries
import seaborn as sns
import pandas as pd
import numpy as np
ship = sns.load_dataset("titanic")
sns.boxplot(x="survived",y="age",data=ship)
plt.show()
sns.boxplot(x="survived",y="age",data=ship)
plt.show()
# libraries
import seaborn as sns
import pandas as pd
import numpy as np
ship = sns.load_dataset("titanic")
sns.boxplot(x="sex",y="fare",data=ship)
plt.show()
sns.boxplot(x="survived",y="age",showmeans=True,data=ship)
plt.show()
sns.boxplot(x="survived",y="age",showmeans=True,
saturation = 1,
meanprops={"marker":"*",
"markersize":"12",
"markeredgecolor":"white"},hue="survived",data=ship)
# Show labels
plt.title("Box plot for survived and age",size=20,weight='bold'),
plt.xlabel("How many Survived")
plt.ylabel("What is the age")
plt.show()
# importing packages
import seaborn
import matplotlib.pyplot as plt
# loading of a dataframe from seaborn
df = seaborn.load_dataset('tips')
############# Main Section #############
# Form a facetgrid using columns with a hue
graph = seaborn.FacetGrid(df, row ='smoker', col ='time')
# map the above form facetgrid with some attributes
graph.map(plt.hist, 'total_bill', bins = 15, color ='orange')
# show the object
plt.show()
# This code is contributed by Deepanshu Rustagi.
# importing packages
import seaborn
import matplotlib.pyplot as plt
sns.boxplot(x="survived",y="age",showmeans=True,
saturation = 1,
meanprops={"marker":"*",
"markersize":"12",
"markeredgecolor":"white"},
hue="survived",data=ship,row)
# Show labels
plt.title("Box plot for survived and age",size=20,weight='bold'),
plt.xlabel("How many Survived")
plt.ylabel("What is the age")
plt.show()
import plotly.express as px
df = px.data.iris()
fig = px.scatter(df,x="sepal_width",y="sepal_length",color="species",
marginal_y="violin",
marginal_x="box",trendline="ols",template="simple_white"
)
fig.show()